<template>
	<view class="conversion">
		<commonHeader :title="$t('aw1')"></commonHeader>
		<view class="gHeadbox"></view>
		<view class="box">
			<view class="box_head">
				<view class="head_name">
					{{$t('aw2')}}（USDT)
				</view>
				<view class="head_num">
					<text class="head_num_money">$</text>
					<text>{{Number(maccount.usdt)}}</text>
				</view>
			</view>
			<view class="boxAddress_s">
				<view class="">
					<view class="boxAddress_s_nadd">
						{{$t('aw3')}}
					</view>
					<view class="boxAddress_s_nadds">
						<input type="text" :placeholder="$t('aw4')" v-model="numbers"/>
						<text class="all" @click="numbers = Number(maccount.usdt)">{{$t('aw5')}}</text>
					</view>
				</view>
				<!-- <view class="inbox">
					<view class="boxAddress_s_nadd">
						提现至：
					</view>
					<view class="boxAddress_s_nadds">
						<input type="text" placeholder="请输入USDT提币地址" />
					</view>
				</view> -->
			</view>
			<view class="boxAddress">
				<view class="boxAddress_nadd">
					{{$t('aw6')}}：
				</view>
				<view class="boxAddress_nadds">
					<input type="password"   v-model="password"   :placeholder="$t('aw7')" />
				</view>
			</view>
			<view class="boxBtn" @click="fnMActivate">
				{{$t('aw8')}}
			</view>
		</view>
	</view>
</template>

<script>
	import {
		memberAccount, //用户资产
		memberWithdraw, //提现
	} from '@/api/home.js'
	export default {
		data() {
			return {
				typeCher: 1,
				password: '',
				numbers:'',
				maccount: '', //用户资产
			}
		},
		mounted() {
			this.fnmemberAccount() // 用户资产
		},
		methods: {
			// 用户资产
			fnmemberAccount() {
				var params = {
					address: this.$store.state.devAddress
				}
				memberAccount(params).then(res => {
					console.log(res)
					if (res.code == 200) {
						this.maccount = res.data
					}
				})
			},
			// 转账
			fnMActivate() {
				if (!this.numbers) {
					uni.showToast({
						icon: 'error',
						title: this.$t('aw9'),
					})
					return;
				} else if (!this.password) {
					uni.showToast({
						icon: 'error',
						title: this.$t('aw10'),
					})
					return;
				}
				var params = {
					address: this.$store.state.devAddress,
					password: this.password,
					num: this.numbers,
				}
				memberWithdraw(params).then(res => {
					console.log(res)
					if (res.code == 200) {
						uni.showToast({
							icon: 'success',
							title: this.$t('aw11'),
						})
						setTimeout(() => {
							console.log('888')
							// 返回上一页并发送事件通知
							uni.navigateBack({
								delta: 1, // 返回的页面数，如果需要返回上一页，delta 设为 1
								success: function() {
									// 通过 eventChannel 向上一页发送事件
									let pages = getCurrentPages();
									let prevPage = pages[pages.length - 2];
									prevPage.$vm.triggerRefresh();
								}
							});
						}, 2000)

					} else {
						uni.showToast({
							icon: 'error',
							title: res.msg,
						})
					}

				})
			},
		}
	}
</script>
<style>
	/deep/.uni-input {
		line-height: 60rpx !important;
	}
</style>
<style scoped lang="scss">
	.box {
		padding: 30rpx;
		box-sizing: border-box;

		&_head {
			background: url('@/static/img/tx.png') no-repeat;
			background-size: cover;
			width: 100%;
			height: 230rpx;
			padding: 30rpx 45rpx;
			box-sizing: border-box;
			position: relative;

			.head_name {
				color: #ffffff;
				font-size: 30rpx;
				font-weight: 500;
				margin-bottom: 24rpx;
			}

			.head_num {
				color: #ffffff;
				font-size: 50rpx;
				display: flex;
				align-items: center;

				&_money {
					color: #ffffff;
					font-size: 32rpx;
					margin-right: 20rpx;
				}
			}

		}

		.boxAddress_s {
			width: 100%;
			margin-top: 55rpx;
			padding: 30rpx 60rpx;
			box-sizing: border-box;
			border-radius: 24rpx;
			opacity: 1;
			background: linear-gradient(137deg, #65008275 0%, #20005e63 100%);
			box-shadow: inset 0 2rpx 6rpx 0 #4545458a, inset 0 0 16rpx 0 #ffffff3b, 4rpx 4rpx 20rpx 0 #00000038;

			.inbox {
				margin-top: 30rpx;
			}

			&_nadd {
				color: #ffffff;
				font-size: 30rpx;
				font-weight: 500;
				margin-bottom: 8rpx;
			}

			&_nadds {
				color: #ffffff;
				font-size: 28rpx;
				font-weight: 400;
				font-family: "苹方";
				border-bottom: 2rpx solid #b1b1b2;
				line-height: 50rpx;
				height: 50rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;

				input {
					line-height: 60rpx !important;
				}


				::placeholder {
					color: #b6b6b6;
					font-size: 24rpx;
					font-weight: 400;
					font-family: "苹方";
				}

				.all {
					color: #d6a7f9;
					font-size: 28rpx;
					font-weight: 900;
				}
			}
		}

		.boxAddress {
			width: 100%;
			border-radius: 24rpx;
			opacity: 1;
			border: 2px solid #979797;
			background: linear-gradient(137deg, #65008275 0%, #20005e63 100%);
			box-shadow: inset 0 2rpx 6rpx 0 #4545458a, inset 0 0 16rpx 0 #ffffff3b, 4rpx 4rpx 20rpx 0 #00000038;
			margin-top: 48rpx;
			padding: 30rpx;
			box-sizing: border-box;

			&_nadd {
				color: #ffffff;
				font-size: 30rpx;
				font-weight: 900;
				font-family: "苹方";
				margin-bottom: 32rpx;
			}

			&_nadds {
				color: #ffffff;
				font-size: 28rpx;
				font-weight: 400;
				font-family: "苹方";
				border-bottom: 2rpx solid #b1b1b2;
				line-height: 60rpx;
				height: 60rpx;

				input {
					line-height: 60rpx;
					font-size: 28rpx;
				}

				::placeholder {

					color: #aaaaac;
					font-size: 28rpx;
					font-weight: 400;
					font-family: "苹方";
				}
			}
		}

		.boxBtn {
			background: url("@/static/img/w.png") no-repeat;
			background-size: contain;
			width: 572rpx;
			height: 78rpx;
			line-height: 78rpx;
			text-align: center;
			color: #ffffff;
			font-size: 42rpx;
			font-weight: 500;
			margin: 150rpx auto;

		}
	}
</style>